package org.example;

import java.lang.reflect.Array;
import java.util.*;

public class ArrayApp {
    public static void main(String[] args) {
        /*1.define
        2.append
        3.access
        4.update
        5.delete
        6.iterate
        7.find
        8.lenth
        9.sort*/
        test();
        ArrayList<Integer> arr = defineArray();
        arr.add(5);   // time complexity: O(1)
        arr.add(2, 99);   // time complexity: O(N)

        Integer integer = arr.get(1);   // time complexity: O(1)

        arr.set(1, 23);  // time complexity: O(1)

        arr.remove(4);  // time complexity: O(N)

        arr.size();  // time complexity: O(1)

        for (int i = 0; i < arr.size(); i++) {  // time complexity: O(N)
            Integer ele = arr.get(i);
            System.out.println("i: "+i+" ele: "+ele);
        }

        arr.contains(5);  // time complexity: O(N)

        Collections.sort(arr);   // time complexity: O(NlogN)
        Collections.sort(arr, Collections.reverseOrder());  // from big to small
    }

    public static ArrayList<Integer> defineArray(){
        // type 01
        int[] a = {1, 2, 3};
        System.out.println("a: "+ Arrays.toString(a));

        // type 02
        int[] b = new int[]{1, 2, 3};
        System.out.println("b: "+ Arrays.toString(b));

        // type 03
        int[] c = new int[3];
        for (int i = 0; i < a.length; i++) {
            c[i] = i + 1;
        }
        System.out.println("c: "+ Arrays.toString(c));

        // type 04
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            arrayList.add(i);
        }
        System.out.println("d: "+ arrayList.toString());

        return arrayList;
    }

    public static void test() {
        int[] a = {1,1,0,1,1,1};
        int cnt = 0;
        int max = 0;
        for (int i = 0; i < a.length; i++) {
            int value = a[i];
            if (value == 1) {
                cnt += 1;
            } else {
                System.out.println("max:"+max+",cnt:"+cnt);
                cnt = 0;
            }
            max = Math.max(max, cnt);
        }
        System.out.println(max);
    }
}
